<?php
/**
 * Created by PhpStorm.
 * User: qhzhyt
 * Date: 2018/10/17
 * Time: 23:28
 */

if (!isset($_POST['mapId']) || !isset($_POST['content']) || $_POST['content'] == null) {
    echo(json_encode(['status' => 0, 'code' => 2]));
    exit(1);
}

session_start();
if (!isset($_SESSION['user'])) {
    echo(json_encode(['status' => 0, 'code' => -1]));
    exit(1);
}
require_once '../conf/conf.php';
$user = $_SESSION['user'];

$mapId = $_POST['mapId'];

$content = $_POST['content'];

$db->insert('map_comment', ['map_id' => $mapId, 'user_id' => $user['user_id'], 'content' => $content]);

$commentId = $db->id();

if ($commentId == 0) {
    echo(json_encode(['status' => 0, 'code' => 0]));
    exit(1);
}

echo json_encode(['status' => 1, 'code' => 1, 'data' => $db->get('map_comment', '*', ['comment_id' => $commentId])]);